package com.ziiwee.reduce.rest.persistent;

import com.ziiwee.reduce.rest.Resource;
import com.ziiwee.reduce.rest.condition.Condition;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;

import java.util.List;
import java.util.Optional;

public interface DataAccessor {

    boolean support(Class<?> entityClass);

    <T> long count(Class<T> entityClass);

    <T> long count(Class<T> entityClass, Condition condition);

    <T> List<T> findAll(Class<T> entityClass);

    <T> List<T> findAll(Class<T> entityClass, Sort sort);

    <T> List<T> findAll(Class<T> entityClass, Condition condition);

    <T> List<T> findAll(Class<T> entityClass, Condition condition, Sort sort);

    <T> Page<T> findPage(Class<T> entityClass, Pageable pageable);

    <T> Page<T> findPage(Class<T> entityClass, Pageable pageable, Condition condition);

    <T> Optional<T> findOne(Class<T> entityClass, Object id);

    <T> Optional<T> findOneByCondition(Class<T> entityClass, Condition condition);

    <T> T save(T t);

    <T> void delete(T t);

    <T> void deleteById(Class<T> entityClass, Object id);

}
